import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ProductsVO, ProductsForm, ProductsQuery } from '@/api/erp/products/types';

/**
 * 查询商品管理列表
 * @param query
 * @returns {*}
 */

export const listProducts = (query?: ProductsQuery): AxiosPromise<ProductsVO[]> => {
  return request({
    url: '/erp/products/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询商品管理详细
 * @param id
 */
export const getProducts = (id: string | number): AxiosPromise<ProductsVO> => {
  return request({
    url: '/erp/products/' + id,
    method: 'get'
  });
};

/**
 * 新增商品管理
 * @param data
 */
export const addProducts = (data: ProductsForm) => {
  return request({
    url: '/erp/products',
    method: 'post',
    data: data
  });
};

/**
 * 修改商品管理
 * @param data
 */
export const updateProducts = (data: ProductsForm) => {
  return request({
    url: '/erp/products',
    method: 'put',
    data: data
  });
};

/**
 * 删除商品管理
 * @param id
 */
export const delProducts = (id: string | number | Array<string | number>) => {
  return request({
    url: '/erp/products/' + id,
    method: 'delete'
  });
};
